<%--
  Created by IntelliJ IDEA.
  User: 林天亮
  Date: 2019/6/18
  Time: 17:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*,java.util.*" errorPage="" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@page isELIgnored="false" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>Title</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<script>
function delaccount(id){
    if(confirm("确定要删除吗？")){
        window.location.href = "emp-delete?id="+id;
    }
}
function updaccount(id) {
        window.location.href = "emp-byId?id="+id;
}
function addaccount(){
    window.location.href="emp_add.jsp";
}

function show(next,total){
    if (next<=0) {
        alert("已经是首页了");
        return;
    }
    if (next>total) {
        alert("已经是尾页了");
        return;
    }
    document.forms[0].action="emp-selectNextPage?page="+next;
    document.forms[0].submit();
}
</script>
<body onload="setit()">
<form id="myForm" name="myForm" method="post">
    <div class="action">
        <div class="t">
            账户管理列表
        </div>
        <div class="pages">
            <table width="90%" border="1" cellpadding="0" cellspacing="0" style="border:thin solid #666; margin-top:20px">
                <tr>
                    <th width="25%">ID</th>
                    <th width="25%">姓名</th>
                    <th width="25%">性别</th>
                    <th width="25%">操作</th>
                </tr>
                <c:if test="${empList!= null}">
                    <c:forEach var="emp" items="${empList}">
                        <tr>
                            <td  align="center">${emp.id}</td>
                            <td  align="center">${emp.name}</td>
                            <td  align="center">${emp.sex}</td>
                            <td  align="center">[<a href="javascript:delaccount('${emp.id}')" style="color:red">删除</a>]
                                [<a href="javascript:updaccount('${emp.id}')" style="color:red">修改</a>]
                            </td>
                            <!-- 传字符串参数时要加引号 -->
                        </tr>
                    </c:forEach>
                </c:if>
                <c:if test="${empList== null}">
                    暂无数据
                </c:if>
            </table>
            <div>
                第${currentPage }页
                <input type="hidden" id="tpage" name="tpage"
                       value="${totalPage} "></input>
                <c:if test="${currentPage>1 }">
                    <input type="button" value="首页" onclick="show(1)"></input>
                    <input type="button" value="上一页" onclick="show(${currentPage-1})"></input>
                </c:if>
                <c:if test="${currentPage<totalPage }">
                    <input type="button" value="下一页" onclick="show(${currentPage+1},${totalPage })"></input>
                    <input type="button" value="尾页" onclick="show(${totalPage})"></input>
                </c:if>
                共${totalPage }页
            </div>
            <br/>
            <br/>
            <div><input type="button"  id="save" value="添加数据" onclick="addaccount()" /></div>
        </div>
    </div>
</form>
</body>
</html>
